﻿/*

Copyright 2009 Guillaume Amringer

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

package {
	import flash.events.Event;
	import flash.events.MouseEvent;
	import lt.uza.utils.Global;
	import org.papervision3d.core.math.Plane3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.events.InteractiveScene3DEvent;
	
	public class Map extends Scene3D {
		
		public var globals:Global = Global.getInstance();
		
		public var startingCoordinates:Array = new Array();
		public var center:DisplayObject3D = new Cube(new MaterialsList({all:new ColorMaterial(0x0000ff)}),100,100);
		public static const RADIUS:int = 10000;
		
		public var playerNumbers:int;
		
		public var floor:Plane3D = new Plane3D();
//		public var BGMaterial:ColorMaterial = new ColorMaterial(0x000000, 1, true);
//		public var sphereBG:Sphere = new Sphere(BGMaterial, Map.RADIUS * 10,16,16);
		
		public function Map(pPlayerNumbers:int = 2):void {
			super();
			
			//	Calculate starting coordinates
			for (var i:int = 0; i < pPlayerNumbers; i++ ) {
				startingCoordinates.push( new StartingPoint(RADIUS * 2 / 3, Math.floor(360 / pPlayerNumbers) * i) );
			}
			
			this.addChild(center);
			
			//	Add mouse click interactivity
//			BGMaterial.doubleSided = true;
//			this.addChild(sphereBG);
//			floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, _floorClickHandler);
//			sphereBG.addEventListener(InteractiveScene3DEvent.OBJECT_RIGHT_RELEASE, _BGRightClickHandler);
		}
		
		public function enterFrameHandler():void {
			globals.game.unitsManager.fireEnterFrameEvent();
		}
		
		private function _floorClickHandler(e:InteractiveScene3DEvent):void {
			globals.game.unitsManager.clearSelection();
		}
/*
		private function _BGRightClickHandler(e:InteractiveScene3DEvent):void {
			globals.game.unitsManager.moveSelection(globals.game.gameInterface.mouse3DPos);
		}
*/
	}
}